import path from "path"
import resret from "../../commonPort/resret"
import isuser from "../../commonPort/isuser"
import {
    readFlie
} from "../../../../fs_file包封装/node_modules/fs_file"
export default function getstudent(req, res) { //获取学生信息列表分页
    //获取请求栏信息对象

    let query = req.query
    let start = query.start * 1
    let end = query.end * 1
    let sort = query.sort * 1 
    console.log(start, end, sort);
    let arr = JSON.parse(readFlie(path.join(__dirname, "../json/student.json")))

    switch (sort) {
        case 1:
            arr.sort((a, b) => {
                return a["sex"] - b["sex"]
            });
            break
        case 2:
            arr.sort((a, b) => {
                return a["age"] - b["age"]
            });
            break
        case 3:
            arr.sort((a, b) => {
                return a["id"] - b["id"]
            });
            break
        case 4:
            arr.sort((a, b) => {
                return a["sum"] - b["sum"]
            });
            break

    }
    console.log(arr);
    let num = Math.ceil(arr.length / end)
    if (start>num) start = num
    let brr = arr.slice((start - 1) * end, start * end)
    //    console.log(brr);

    resret({
        res,
        text: JSON.stringify({
            state: "001",
            num,
            starts,
            data: brr
        })
    })
    return true;
}